package cn.com.dcsgo.controller;

import cn.com.dcsgo.dto.OrderConfirmDTO;
import cn.com.dcsgo.dto.OrderSubmitDTO;
import cn.com.dcsgo.dto.PageDTO;
import cn.com.dcsgo.model.Result;
import cn.com.dcsgo.service.OrderService;
import cn.com.dcsgo.utils.AuthUtil;
import cn.com.dcsgo.vo.OrderAmountVO;
import cn.com.dcsgo.vo.OrderConfirmVO;
import cn.com.dcsgo.vo.OrderSubmitVO;
import cn.com.dcsgo.vo.OrderVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 小程序端订单相关接口
 *
 * @author Dcsgo
 * @since 2025/11/16 13:55
 */
@Tag(name = "小程序端订单相关接口")
@RestController
@RequestMapping("p/myOrder")
public class MiniAppOrderController {
    @Resource
    private OrderService orderService;

    @GetMapping("orderCount")
    @Operation(summary = "获取订单数量信息")
    public Result<OrderAmountVO> getOrderAmountVO() {
        return Result.success(orderService.getOrderAmountVO(AuthUtil.getOpenid()));
    }

    @GetMapping("myOrder")
    @Operation(summary = "分页获取订单信息")
    public Result<Page<OrderVO>> getOrderVOPage(@RequestParam("status") Integer status, PageDTO pageDTO) {
        return Result.success(orderService.getOrderVOPage(AuthUtil.getOpenid(), status, pageDTO));
    }

    @PostMapping("confirm")
    @Operation(summary = "确认订单")
    public Result<OrderConfirmVO> confirmOrder(@RequestBody OrderConfirmDTO orderConfirmDTO) {
        // TODO 这里收货地址使用会员默认收货地址，前端是没有给收货地址的，不太合理！
        return Result.success(orderService.confirmOrder(orderConfirmDTO));
    }

    @PostMapping("submit")
    @Operation(summary = "提交订单")
    public Result<OrderSubmitVO> submitOrder(@Validated @RequestBody OrderSubmitDTO orderSubmitDTO) {
        return Result.success(orderService.submitOrder(orderSubmitDTO));
    }
}
